import Vue from "vue";


import Vuex from "vuex"
import {
  setItem,
  getItem,
  removeItem
} from '../utils/storage'
import persistedState from 'vuex-persistedstate'
Vue.use(Vuex)
const TOKEN_KEY = 'TOKEN_EMAIL'

const store = new Vuex.Store({
  plugins: [persistedState()],
  state: {
    Introduction: getItem('list'),
    Parameters: '',
    SizeID: 0,
    size: [],
    color: [],
    emailLogin: getItem(TOKEN_KEY),
    CatList: getItem('CatList'),
    TypeList: getItem('TypeList'),
    CheckoutList: getItem('checkoutList'),
    Totol: getItem('Totol'),
    Address: getItem('Address'),
    SelectAddress: getItem('SelectAddress'),

    time: getItem('time'),
    OrderNum: getItem('OrderNum'),
    recList: getItem('recList'),
    Takedelivery: getItem('delivery'),
    orderID: getItem('orderID'),
    Goodsid: getItem('Goodsid'),
    RecentSearch: getItem('RecentSearch'),
    goodsRecentSearch: getItem('goodsRecentSearch'),
    friID: getItem('friID'),
    chatName: getItem('chatName'),
    requestList: getItem('requestList'),
    redPackageTime: getItem('redPackageTime'),
    redPackageInfo: getItem('redPackageInfo'),
    count: [],
    orderCount: 0,
    RecentlyGoods: [],
    OrdersNum: 0,
    Jingwei: null,
    orderPic: "",



  },
  mutations: {
    increment(state, list) {
      // 变更状态
      state.Introduction = list
      setItem('list', list)
    },
    getParameters(state, params) {

      state.Parameters = params
    },
    getSize(state, size) {
      state.size = size

    },
    getSizeID(state, size) {
      state.SizeID = size

    },
    getColor(state, color) {
      state.color = color
    },
    setUser(state, user) {
      state.emailLogin = user
      setItem(TOKEN_KEY, user)
    },
    deleteUser(state, user) {
      state.emailLogin = user
    },
    setCatList(state, list) {
      state.CatList = list
      setItem('CatList', list)
    },
    setTypeList(state, list) {
      state.TypeList = list
      setItem('TypeList', list)
    },
    setCheckoutList(state, list) {
      state.CheckoutList = list
      setItem('checkoutList', list)
    },
    setTotol(state, price) {
      state.Totol = price
      setItem('Totol', price)
    },
    setAddress(state, list) {
      state.Address = list
      setItem('Address', list)
    },
    setSelectAddress(state, list) {
      state.SelectAddress = list
      setItem('SelectAddress', list)
    },
    setTime(state, list) {
      state.time = list
      setItem('time', list)
    },
    setOrderNum(state, list) {
      state.OrderNum = list
      setItem('OrderNum', list)
    },
    setRecList(state, list) {
      state.recList = list
      setItem('recList', list)
    },
    setTakedelivery(state, list) {
      state.Takedelivery = list
      setItem('delivery', list)
    },
    setOrderID(state, list) {
      state.orderID = list
      setItem('orderID', list)
    },
    setGoodsid(state, list) {
      state.Goodsid = list
      setItem('Goodsid', list)
    },
    setRecentSearch(state, list) {
      state.RecentSearch = list
      setItem('RecentSearch', list)
    },
    setgoodsRecentSearch(state, list) {
      state.goodsRecentSearch = list
      setItem('goodsRecentSearch', list)
    },
    setfriID(state, list) {
      state.friID = list
      setItem('friID', list)
    },
    setchatName(state, list) {
      state.chatName = list
      setItem('chatName', list)
    },
    setrequestList(state, list) {
      state.requestList.push(list)

    },
    setredPackageTime(state, list) {
      state.redPackageTime = list
      setItem('redPackageTime', list)
    },
    setredPackageInfo(state, list) {
      state.redPackageInfo = list
      setItem('redPackageInfo', list)
    },
    setCount(state, str) {

      let list = []
      list.push(str)
      state.count = [...state.count, ...list]

      // setItem('count', state.count)
    },
    deletecount(state, id) {
      state.count.map((v, i) => {
        if (v.GoodsID == id) {
          state.count.splice(i, 1)
        }
      })
    },
    delechkoutlist(state, stre) {
      state.CheckoutList = stre
    },
    setOrderCount(state, num) {
      state.orderCount = num
    },
    setRecentlyGoods(state, str) {

      let list = []

      list.push(str)
      state.RecentlyGoods = [...state.RecentlyGoods, ...list]





    },
    setOrdersNum(state, str) {
      state.OrdersNum = str
    },
    setJingwei(state, str) {
      state.Jingwei = str
    },
    setOrdersPic(state, str) {
      state.orderPic = str
    },
  },
  getters: {

  },
  actions: {

  }
})
export default store